package com.tssm.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tssm.bean.SupplyBean;
import com.tssm.common.services.BaseServiceImpl;
import com.tssm.dao.SarcFeedbackDAO;
import com.tssm.dao.SarcSupplierDAO;
import com.tssm.pojo.SarcFeedback;
import com.tssm.pojo.SarcSupplier;
import com.tssm.service.SarcSupplierService;
@Service("sarcsupplierService")
public class SarcSupplierServiceImpl extends BaseServiceImpl<SarcSupplier>
		implements SarcSupplierService {
	@Resource
	private SarcSupplierDAO sarcsupplierDAO;
	@Resource
	private SarcFeedbackDAO sarcfeedbackDAO;

	/**
	 * 
	 * 
	 * 
	 * @方法说明: 根据用户名查找用户是否存在
	 * @param account
	 *            用户名
	 * @return
	 * @作者:徐龙
	 * @日期:2012-1-11
	 */
	public SarcSupplier findUserIsExist(String account) {
		return sarcsupplierDAO.findUserIsExist(account);
	}

	/**
	 * 
	 * 
	 * 
	 * @方法说明: 查找E-mail是否已被使用
	 * @param email
	 * @return
	 * @作者:徐龙
	 * @日期:2012-1-11
	 */
	public boolean findEmailIsExist(String email) {
		return sarcsupplierDAO.findEmailIsExist(email);
	}

	/**
	 * 
	 * 
	 * 
	 * @方法说明: 根据用户名和密码查找
	 * @param account
	 *            用户名 或 企业名称
	 * @param passowrd
	 *            用户密码
	 * @return
	 * @作者:徐龙
	 * @日期:2012-1-15
	 */
	public SarcSupplier findByUserAccount(String account, String passowrd) {
		return sarcsupplierDAO.findByUserAccount(account, passowrd);
	}

	public List<SupplyBean> findAllSupply() {
		return sarcsupplierDAO.findAllSupply();
	}
	/**
	 * 根据供应商名查找质量反馈单
	 */
	public List<SarcFeedback> findFeedbackBySupplierName(String supplierName){
		List<SarcFeedback> sfnewlist=new ArrayList<SarcFeedback>();
		List<SarcFeedback> sflist=sarcfeedbackDAO.findFeedbackBySupplierName(supplierName);
		for (SarcFeedback feedback:sflist){
			Date ntime = new Date();
			Date replydead=feedback.getReplyDeadline();
			if (ntime.getTime()>replydead.getTime()){
				feedback.setDef9("1");
			}
			sfnewlist.add(feedback);
		}
		return sfnewlist;
	}
	/**
	 * 
	  * 
	  * 
	  * @方法说明: 单查质量反馈单
	  * @param id
	  * @return
	  * @作者:徐龙
	  * @日期:2012-2-24
	 */
	public SarcFeedback getFeedbackById(Long id){
		return sarcfeedbackDAO.get(SarcFeedback.class, id);
	}
	/**
	 * 
	  * 
	  * 
	  * @方法说明: 保存或修改质量反馈单
	  * @param sarcFeedback
	  * @return
	  * @作者:徐龙
	  * @日期:2012-2-24
	 */
	public boolean saveOrupdateSarcFeedback(SarcFeedback sarcFeedback){
		return sarcfeedbackDAO.saveOrUpdate(sarcFeedback);
	}

	public SarcSupplierDAO getSarcsupplierDAO() {
		return sarcsupplierDAO;
	}

	public void setSarcsupplierDAO(SarcSupplierDAO sarcsupplierDAO) {
		this.sarcsupplierDAO = sarcsupplierDAO;
	}
}
